Fix bug in 'todo-jump-to-category' (bug#78608)
authorStephen Berman <stephen.berman@gmx.net>
Wed, 28 May 2025 15:17:23 +0000 (17:17 +0200)
committerStephen Berman <stephen.berman@gmx.net>
Wed, 28 May 2025 15:17:23 +0000 (17:17 +0200)
* lisp/calendar/todo-mode.el (todo-jump-to-category): Eliminate
comparison of the number of Todo categories before and after
specifying the category to jump to and replace it by a check of
whether there are any items in the category, since an existing
category should always have at least one item (perhaps done or
archived).

lisp/calendar/todo-mode.el

index 652176af3b1ed9d28d6bde9dc8520b3be321d780..6fee0ce29508ccb307ea78f34ada7bbaafc07d93 100644 (file)
@@ -952,12 +952,9 @@ Categories mode."
                                 todo-current-todo-file) ".toda")
                      ;; Otherwise, jump to the category in the todo file.
                      todo-current-todo-file)))
-          (len (length todo-categories))
           (cat+file (unless cat
                       (todo-read-category "Jump to category: "
                                            (if archive 'archive) file)))
-          (add-item (and todo-add-item-if-new-category
-                         (> (length todo-categories) len)))
           (category (or cat (car cat+file))))
       (unless cat (setq file0 (cdr cat+file)))
       (with-current-buffer (find-file-noselect file0 'nowarn)
@@ -971,7 +968,10 @@ Categories mode."
         (todo-category-select)
         (goto-char (point-min))
        (if (bound-and-true-p hl-line-mode) (hl-line-highlight))
-        (when add-item (todo-insert-item--basic))))))
+        (when (and todo-add-item-if-new-category
+                   ;; A new category is empty on creation.
+                   (seq-every-p #'zerop (cdr (assoc category todo-categories))))
+          (todo-insert-item--basic))))))
 
 (defun todo-next-item (&optional count)
   "Move point down to the beginning of the next item.